//
//  NSString+Category.m
//  OrcGolfNew
//
//  Created by apple on 16/7/18.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "NSString+Category.h"
//#import "NSString+SBJSON.h"

@implementation NSString (NSString_Category)

+(NSString *)toString:(NSString *)inStr
{
    if (inStr==nil || [inStr isEqual:[NSNull null]]) {
        return @"";
    }
    return [NSString stringWithFormat:@"%@",inStr];
}

/**
 *  删除字符串头部字符
 *
 *  @param characterSet [NSCharacterSet whitespaceAndNewlineCharacterSet] 删除字符串左侧的空格和换行符 or [NSCharacterSet whitespaceCharacterSet] 不删除换左侧行符和新行，只去除空格
 *
 *  @return 删除后的字符串
 */
- (NSString *)stringByTrimmingLeadingCharactersInSet:(NSCharacterSet *)characterSet;
{
    return @"";
}

/**
 *  删除字符串左侧的空格和换行符
 *
 *  @return 删除后的字符串
 */
- (NSString *)stringByTrimmingLeadingWhitespaceAndNewlineCharacters
{
    return @"";
}

/**
 *  删除字符串尾部字符
 *
 *  @param characterSet [NSCharacterSet whitespaceAndNewlineCharacterSet] 删除字符串左侧的空格和换行符 or [NSCharacterSet whitespaceCharacterSet] 不删除换左侧行符和新行，只去除空格
 *
 *  @return 删除后的字符串
 */
- (NSString *)stringByTrimmingTrailingCharactersInSet:(NSCharacterSet *)characterSet
{
    return @"";
}

/**
 *  删除字符串右侧的空格和换行符
 *
 *  @return 删除后的字符串
 */
- (NSString *)stringByTrimmingTrailingWhitespaceAndNewlineCharacters
{
    return @"";
}


/**
 *  判断是否手机号码
 *
 *  @return YES / NO
 */
- (BOOL)isMobileNumber
{
    if (self.length==11 && [self hasPrefix:@"1"]) {
        return YES;
    }
    return NO;
}


/**
 *  处理电话号码，去除多余的字符,'-' '(' ')' '+86'等，得到纯粹的，干净的号码
 *
 *  @return 过滤后的电话号码
 */
- (NSString *)phoneNumberFilter
{
    return @"";
}


/**
 *  字符串是否为空
 *
 *  @return YES / NO
 */
- (BOOL)isEmpty;
{
    if ([self isEqual:[NSNull null]]) {
        return YES;
    }
    if (self == nil) {
        return YES;
    }
    if (self.length==0) {
        return YES;
    }
    return NO;
}


/**
 *  判断名称是否合法
 *
 *  @return YES / NO
 */
- (BOOL)isNameValide
{
    return YES;
}


- (NSURL *)URLString
{
    NSString *str = self;
    if ([str isEqual:[NSNull null]]) {
        str = @"";
    }
    return [NSURL URLWithString:str];
}

// 根据时间戮  拿到时间
+ (instancetype)DateFormatWithDateChuo:(NSInteger )timeChuo
{
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:timeChuo];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy年MM月dd日 aa HH:mm"];
    NSString *timeStamp = [formatter stringFromDate:date];
    return timeStamp;
}
+ (instancetype)DateFormatWithDateChuo:(NSInteger )timeChuo withFormat:(NSString *)formatString
{
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:timeChuo];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:formatString];
    NSString *timeStamp = [formatter stringFromDate:date];
    return timeStamp;
}

/*   2016-08-12T20:04:07  转为 月、日  */
+(instancetype)DateStringFromTime:(NSString *)strDate
{
    return @"";
//    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
//    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
//    NSDate *date = [formatter dateFromString:strDate];
//    [formatter setDateFormat:@"mm-dd"];
//    return [formatter stringFromDate:date];
}
/**
 *  得到cell上显示的日期
 *
 *  @param date 日期
 *
 *  @return cell显示的字符串
 */
+ (instancetype)cellDateFormatWithDate:(NSDate *)date;
{
    
    return @"";
}

/**
 *  得到cell上显示的日期
 *
 *  @param date 字符串string data, eg:2015-1-1 12:12:12
 *
 *  @return cell显示的字符串
 */
+ (instancetype)cellDateFormatWithStringDate:(NSString *)strDate;
{
    return @"此方法已经停用";
}

/**
 *  得到cell上显示的日期, 显示格式: 刚刚，几小时前，几个月头，几年前
 *
 *  @param date 日期
 *
 *  @return cell显示的字符串
 */
+ (instancetype)cellDateAgoFormatWithDate:(NSDate *)date;
{
    return @"";
}

/**
 *  得到cell上显示的日期, 显示格式: 刚刚，几小时前，几个月头，几年前
 *
 *  @param date 字符串string data, eg:2015-1-1 12:12:12
 *
 *  @return cell显示的字符串
 */
- (NSString*)cellDateAgoFormatWithStringDate;
{
    return @"";
}


-(NSString *)localVideoFile
{
    return [NSString stringWithFormat:@"%@%@.mp4",[NSString videoPath],self];
}  

+ (NSString *)uuid{
    // create a new UUID which you own
    CFUUIDRef uuidref = CFUUIDCreate(kCFAllocatorDefault);
    
    // create a new CFStringRef (toll-free bridged to NSString)
    // that you own
    CFStringRef uuid = CFUUIDCreateString(kCFAllocatorDefault, uuidref);
    
    NSString *result = (__bridge NSString *)uuid;
    //release the uuidref
    CFRelease(uuidref);
    // release the UUID
    CFRelease(uuid);
    
    return result;
}





@end
